<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        header {
            width: 100%;
            height: 50px;
            display: flex;
        }

        header .tab {
            flex: 1;
            outline: 1px solid red;
        }

        header .tab.active {
            background: salmon;
        }

        .content {
            display: none;
        }

        .content.active {
            display: block;
        }

    </style>
</head>
<body>
    <!-- 1. HTML/CSS -->
    <!-- 2. js选择器 -->
    <!-- 3. 添加事件 -->
    <header>
        <div class="tab active">1</div>
        <div class="tab">2</div>
        <div class="tab">3</div>
    </header>

    <div class="content active">11111111111</div>
    <div class="content">22222222222</div>
    <div class="content">33333333333</div>

    <script>

        const tabList = document.querySelectorAll('header .tab');
        const contentList = document.querySelectorAll('.content');

        for (let i = 0; i < tabList.length; i++) {
            tabList[i].addEventListener('click', function () {
                // 1. 清除所有的active
                for (let j = 0; j < tabList.length; j++) {
                    tabList[j].setAttribute('class', 'tab');
                    contentList[j].setAttribute('class', 'content');
                }
                // 2. 把第i个tab加一个.active  把第i个content加一个.active
                tabList[i].setAttribute('class', 'tab active');
                contentList[i].setAttribute('class', 'content active');
            });
        }


    </script>

</body>
</html>